package com.blog.controller;

import java.io.IOException;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import net.sf.json.JSONArray;

import org.apache.struts2.ServletActionContext;

import com.blog.pojo.User;
import com.blog.services.IUserService;
import com.blog.utils.ResponseUtil;
import com.opensymphony.xwork2.Action;

/**
 * 登录页面
 * 
 * @author ZhangBo
 * 
 */
public class LoginAction {

	private IUserService userService;

	public void setUserService(IUserService userService) {
		this.userService = userService;
	}

	User user = new User();

	public User getUser() {
		return user;
	}

	public void setUser(User user) {
		this.user = user;
	}

	public String login$() throws IOException {
		boolean b = this.userService.login(getUser());
		JSONArray json = JSONArray.fromObject(b);
		ResponseUtil.out(json.toString());
		return null;
	}

	public String login() throws IOException {

		return Action.SUCCESS;
	}

	public String logout() throws IOException {
		HttpServletResponse response = ServletActionContext.getResponse();
		response.getWriter().write("访问的是 logout 法轮功 方法！共产党共产党共产党");
		System.out.println("logout()");
		return null;
	}

	public String adminLogin() throws IOException {
		HttpServletResponse response = ServletActionContext.getResponse();
		response.getWriter().write("访问的是 adminLogin 方法！");
		return null;
	}

	public String adminLogout() throws IOException {
		HttpServletResponse response = ServletActionContext.getResponse();
		response.getWriter().write("访问的是 adminLogout 方法！");
		return null;
	}
}
